package com.east.manager;

import cn.hutool.db.handler.HandleHelper;
import com.east.dto.NameValueDTO;
import com.east.mapper.ActivityMapper;
import com.east.mapper.ClueMapper;
import com.east.mapper.CustomerMapper;
import com.east.mapper.TranMapper;
import com.east.result.Result;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Component
public class StatisticManager {
    @Resource
    private ActivityMapper activityMapper;
    @Resource
    private ClueMapper clueMapper;
    @Resource
    private CustomerMapper customerMapper;
    @Resource
    private TranMapper tranMapper;

    public Result getStatisticalData() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("totalActivityNum", activityMapper.totalNum());
        map.put("totalOngoingActivityNum", activityMapper.ongoingTotalNum());
        map.put("totalClueNum", clueMapper.totalNum());
        map.put("totalCustomer", customerMapper.totalNum());
        map.put("dealMoney", tranMapper.dealMoney());
        map.put("allMoney", tranMapper.allMoney());
        return Result.OK(map);
    }

    public Result getSaleFunnelData() {
        ArrayList<Object> list = new ArrayList<>();
        list.add(NameValueDTO.builder().name("线索").value(clueMapper.totalNum()).build());
        list.add(NameValueDTO.builder().name("客户").value(customerMapper.totalNum()).build());
        list.add(NameValueDTO.builder().name("交易").value(tranMapper.tranNum()).build());
        list.add(NameValueDTO.builder().name("成交").value(tranMapper.dealNum()).build());
        return Result.OK(list);
    }

    public Result getCluePieData() {

      List<NameValueDTO> list = clueMapper.sourceTotalCount();
      return Result.OK(list);
    }
}
